package com.og.managedbean;

import java.io.Serializable;

import javax.enterprise.context.SessionScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;

import com.og.backingbean.Status;
import com.og.dao.CRUDEntityDAO;

/**
 * @author Renaud DIANA
 *
 */
@Named
@SessionScoped
public class StatusBean implements Serializable {

	private static final long serialVersionUID = 1L;
	
	/* Dependency injection */
	// Model
    @Inject
    private CRUDEntityDAO<Status> statusDAO;
    // BackingBean
    @Inject
    private Status status;
    @Inject
    private ListBean list;

	/**
	 * Default constructor
	 */
	public StatusBean() {
		// TODO Auto-generated constructor stub
	}
	
	public String create() {
		
		// Call model				
		statusDAO.createEntity(status);
								
		// Generate new list
		list.findAllStatus();
				
		// Clear form
		status = new Status();
		
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Create Status Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}

	public String update() {
		
		// Call model				
		statusDAO.updateEntity(status);
		
		// Generate new list
		list.findAllStatus();
				
		// Clear form
		status = new Status();
				
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Update status Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}
	
	public String delete() {
				
		// Call model				
		statusDAO.deleteEntity(status);
		
		// Generate new list
		list.findAllStatus();
				
		// Clear form
		status = new Status();
				
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Delete status Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}
	
	public String findOne() {
		
		// Call model				
		status = statusDAO.findOneEntity(status, status.getIdStatus());
		
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Find status Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}
	
	// Getters and Setters
	
	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

}
